﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace CapstoneMockup
{
    public partial class TimeStampViewer : PhoneApplicationPage
    {

        public static WeeklyTimeStamps wts;
        public ObservableCollection<Timestamps> listOfHours;

        public TimeStampViewer()
        {
            InitializeComponent();
            listOfHours = App.ViewModel.User._hourTimeStamps;
            CreateVisualTimeStamps();
        }

        private void CreateVisualTimeStamps()
        {
            if (App.ViewModel.IsDataLoaded)
                ListOfHoursBox.ItemsSource = App.ViewModel.TimeStampItems;
        }

        private void ListOfHoursBox_SelectionChanged(Object sender, RoutedEventArgs args)
        {
            if (ListOfHoursBox.SelectedIndex == -1)
                return;

            NavigationService.Navigate(new Uri("/WeeklyTimeStampViewer.xaml?selectedItem=" + ListOfHoursBox.SelectedIndex, UriKind.Relative));

            ListOfHoursBox.SelectedIndex = -1;
        }
    }

    public class WeeklyTimeStamps
    {
        public string weekRange;
        public ObservableCollection<Timestamps> weeklyTimeStamps;
        public string totalHours;

        public WeeklyTimeStamps(ObservableCollection<Timestamps> listOfHours)
        {
            weekRange = "" + listOfHours.Min(ts => ts.StartTime).ToShortDateString() +
                " - " + listOfHours.Max(ts => ts.EndTime).ToShortDateString();
            weeklyTimeStamps = listOfHours;
            totalHours = new Timestamps().TotalHoursAndMinutes(listOfHours);
        }
    }
}